package com.aaa.sys.service.impl;

import com.aaa.sys.entity.OperationLog;
import com.aaa.sys.mapper.OperationLogMapper;
import com.aaa.sys.service.OperationLogService;
import com.aaa.sys.vo.OperationLogResult;
import com.aaa.sys.vo.OperationLogVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 操作日志 服务实现类
 * </p>
 *
 * @author ykq
 * @since 2020-12-08
 */
@Service
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, OperationLog> implements OperationLogService {

    @Autowired
    private OperationLogMapper operationLogMapper;
    @Override
    public IPage<OperationLogResult> findByCondition(Integer current, Integer limit, OperationLogVo operationLogVo) {
        String endTime = operationLogVo.getEndTime();
        String startTime = operationLogVo.getStartTime();
        String logType = operationLogVo.getLogType();
        String logName = operationLogVo.getLogName();
        QueryWrapper<OperationLogResult> wrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(endTime)){
             wrapper.le("o.create_time",endTime.substring(0,10));
        }

        if(StringUtils.isNotEmpty(startTime)){
            wrapper.ge("o.create_time",startTime.substring(0,10));
        }

        if(StringUtils.isNotEmpty(logType)){
             wrapper.eq("log_type",logType);
        }
        if(StringUtils.isNotEmpty(logName)){
            wrapper.like("log_name",logName);
        }

        IPage<OperationLogResult> page=new Page<>(current,limit);



        return this.operationLogMapper.findByCondition(page,wrapper);
    }
}
